package com.woniuxy.businessassembly.service.impl;

import com.woniuxy.businessassembly.dao.HotelPolicyMapper;
import com.woniuxy.businessassembly.form.FacilitiesForm;
import com.woniuxy.businessassembly.form.ServerForm;
import com.woniuxy.businessassembly.model.HotelFacilities;
import com.woniuxy.businessassembly.model.HotelInfo;
import com.woniuxy.businessassembly.model.HotelServer;
import com.woniuxy.businessassembly.dao.HotelServerMapper;
import com.woniuxy.businessassembly.service.IHotelServerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Kevin Kwok
 * @since 2021-05-24
 */
@Service
public class HotelServerServiceImpl extends ServiceImpl<HotelServerMapper, HotelServer> implements IHotelServerService {

    @Resource
    private HotelServerMapper serverMapper;
    @Resource
    private HotelPolicyMapper policyMapper;


    @Override
    public List<ServerForm> queryAllServerByName(String hotelName) {
        /*构建一个服务展示form，每个form只是其中一个服务，用list来提现所有的服务 */
        List<ServerForm> serverForms = new ArrayList<>();
        /*根据酒店名字查询出酒店的id*/
        HotelInfo query = policyMapper.queryByName(hotelName);

        /*根据酒店ID查询这个酒店具有的所有服务集合，遍历这个集合*/
        List<HotelServer> hotelServers = serverMapper.queryAllServer(query.getHotelId());
        for (int i = 0; i < hotelServers.size(); i++) {
            /*得到某条server*/
            HotelServer hotelServer = hotelServers.get(i);
            /*创建serverForm*/
            ServerForm serverForm = new ServerForm();
            //将查询出来的hotelServer存入serverForm里面去
            serverForm.setHotelServer(hotelServer);
            serverForms.add(serverForm);
            Integer hotelServerId = hotelServer.getHotelServerId();
            //查询一条serverID对应的facilities集合
            List<HotelFacilities> hotelFacilities = serverMapper.queryAllFacilities(hotelServerId);
            /*将查询出来的集合封装到serverForm里面去,至此，serverForm整合完毕*/
            serverForm.setFacilities(hotelFacilities);
        }
        
        return serverForms;
    }

}
